darwin pgsql patches - Mailing list pgsql-patches

From Peter Bierman
Subject darwin pgsql patches
Date
Msg-id v03130301b64a66cf7732@[17.202.21.230]
Whole thread Raw
Responses Re: darwin pgsql patches
Re: darwin pgsql patches
List pgsql-patches
Here are patches to CVS top of tree that allow darwin to completely
build and install. Unfortunately, the sem...() shim does not function
correctly yet, so it's not stable enough to use. With luck I'll be able to
get it working before 7.1 goes final. But the addition of these patches
and new files is a big step towards support for Mac OS X. (Please make sure
that the Makefile patches have tabs in the correct locations.)

Questions or comments to pmb@mac.com please.

Thanks!

-pmb


new directory:
 src/backend/port/darwin/
===================================================================

new file:
 src/backend/port/darwin/Makefile
===================================================================
#-------------------------------------------------------------------------
#
# Makefile--
#    Makefile for port/darwin
#
# IDENTIFICATION
#    $Header: $
#
#-------------------------------------------------------------------------

subdir = src/backend/port/darwin
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global

OBJS = sem.o

all: SUBSYS.o autotestsem

SUBSYS.o: $(OBJS)
        $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)

autotestsem: autotestsem.o sem.o
        $(CC) -o autotestsem sem.o autotestsem.o

depend dep:
        $(CC) -MM $(CFLAGS) *.c >depend

clean:
        rm -f SUBSYS.o $(OBJS) autotestsem autotestsem.o

ifeq (depend,$(wildcard depend))
include depend
endif
===================================================================

new file:
 src/backend/port/darwin/autotestsem.c
===================================================================
/*-------------------------------------------------------------------------
 *
 * autotestsem.c
 *        Test of System V Semaphore Emulation
 *
 * Copyright (c) 2000, Peter Bierman
 *
 * IDENTIFICATION
 *        $Header: $
 *
 *-------------------------------------------------------------------------
 */

/* placeholder file for a self-test program I plan to write.  pmb-001128 */

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "postgres.h"
#include "storage/ipc.h"
#include <sys/mman.h>
#include "sem.h"

int
main(int argc, char **argv)
{
        return 0;
}
===================================================================

new file:
 src/backend/port/darwin/sem.c
instructions:
 cp src/backend/port/qnx4/sem.c src/backend/port/darwin/sem.c
 then apply patch:
===================================================================
--- ../qnx4/sem.c       Wed Apr 12 10:15:30 2000
+++ sem.c       Tue Nov 28 22:40:40 2000
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /home/projects/pgsql/cvsroot/pgsql/src/backend/port/qnx4/sem.c,v 1.3 2000/04/12 17:15:30 momjian Exp
$
+ *       $Header: $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,11 +22,12 @@
 #include "postgres.h"
 #include "storage/ipc.h"
 #include "storage/proc.h"
-#include <sys/sem.h>
+//#include <sys/sem.h>
+#include "sem.h"


-#define SETMAX ((MAXBACKENDS + PROC_NSEMS_PER_SET - 1) / PROC_NSEMS_PER_SET)
-#define SEMMAX (PROC_NSEMS_PER_SET)
+#define SEMMAX (IPC_NMAXSEM)
+#define SETMAX ((MAXBACKENDS + SEMMAX - 1) / SEMMAX)
 #define OPMAX  8

 #define MODE   0700
@@ -135,6 +136,9 @@

        if (nsems < 0 || nsems > SEMMAX)
        {
+#ifdef DEBUG_IPC
+               fprintf(stderr, "darwin semget aborting because nsems out of range. (%d)\n", nsems);
+#endif
                errno = EINVAL;
                return -1;
        }
@@ -152,7 +156,7 @@
                if (fd == -1)
                        return fd;
                /* The size may only be set once. Ignore errors. */
-               ltrunc(fd, sizeof(struct sem_info), SEEK_SET);
+               ftruncate(fd, sizeof(struct sem_info));
                SemInfo = mmap(NULL, sizeof(struct sem_info),
                                           PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
                if (SemInfo == MAP_FAILED)
@@ -196,6 +200,10 @@
                        {
                                if (nsems != 0 && SemInfo->set[semid].nsems < nsems)
                                {
+#ifdef DEBUG_IPC
+fprintf(stderr, "darwin: semget failed because if (nsems != 0 && SemInfo->set[semid].nsems < nsems) %d %d\n",
+       nsems, SemInfo->set[semid].nsems);
+#endif
                                        sem_post(&SemInfo->sem);
                                        errno = EINVAL;
                                        return -1;
@@ -212,6 +220,9 @@
                semid++;
        if (semid >= SETMAX)
        {
+#ifdef DEBUG_IPC
+fprintf(stderr, "darwin: semget failed because all keys were -1 up to SETMAX\n");
+#endif
                sem_post(&SemInfo->sem);
                errno = ENOSPC;
                return -1;
===================================================================

new file:
 src/backend/port/darwin/sem.h
instructions:
 cp src/backend/port/qnx4/sem.h src/backend/port/darwin/sem.h
 then apply patch:
===================================================================
--- ../qnx4/sem.h       Wed Apr 12 10:15:30 2000
+++ sem.h       Tue Nov 28 22:42:13 2000
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /home/projects/pgsql/cvsroot/pgsql/src/backend/port/qnx4/sem.h,v 1.3 2000/04/12 17:15:30 momjian Exp
$
+ *       $Header: $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,6 +15,9 @@
 #ifndef _SYS_SEM_H
 #define _SYS_SEM_H

+/* Darwin's sem... shim doesn't quite work yet, best to leave this turned on for now */
+#define DEBUG_IPC
+
 #include <sys/ipc.h>

 #ifdef __cplusplus
@@ -33,6 +36,10 @@
 #define GETZCNT 7                              /* get semzcnt */
 #define SETVAL 8                               /* set semval */
 #define SETALL 9                               /* set all semval's */
+
+#ifndef ushort_t
+#define ushort_t unsigned int
+#endif

 /*
  *     There is one semaphore structure for each semaphore in the system.
===================================================================


Index: Makefile.in
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/port/Makefile.in,v
retrieving revision 1.27
diff -u -r1.27 Makefile.in
--- Makefile.in 2000/10/20 21:03:45     1.27
+++ Makefile.in 2000/11/29 06:50:42
@@ -30,6 +30,9 @@
 ifeq ($(PORTNAME), beos)
 OBJS += beos/SUBSYS.o
 endif
+ifeq ($(PORTNAME), darwin)
+OBJS += darwin/SUBSYS.o
+endif
 all: SUBSYS.o

 SUBSYS.o: $(OBJS)
@@ -45,11 +48,19 @@
 beos.dir:
        $(MAKE) -C beos all

+darwin/SUBSYS.o: darwin.dir
+
+darwin.dir:
+       $(MAKE) -C darwin all
+
 tas.o: tas.s
        $(CC) $(CFLAGS) -c $<

 distclean clean:
        rm -f SUBSYS.o $(OBJS)
+       $(MAKE) -C darwin clean
+       $(MAKE) -C beos clean
+       $(MAKE) -C qnx4 clean

 depend dep:
        $(CC) -MM $(CFLAGS) *.c >depend
Index: src/backend/port/dynloader/darwin.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/port/dynloader/darwin.c,v
retrieving revision 1.3
diff -u -r1.3 darwin.c
--- src/backend/port/dynloader/darwin.c    2000/11/14 21:26:21    1.3
+++ src/backend/port/dynloader/darwin.c    2000/11/29 05:48:51
@@ -10,7 +10,7 @@
 #include <mach-o/dyld.h>
 #include "dynloader.h"

-void *pg_dlopen(const char *filename)
+void *pg_dlopen(char *filename)
 {
     NSObjectFileImage image;

@@ -26,7 +26,7 @@
     return;
 }

-PGFunction pg_dlsym(void *handle, const char *funcname)
+PGFunction pg_dlsym(void *handle, char *funcname)
 {
     NSSymbol symbol;
     char *symname = (char*)malloc(strlen(funcname)+2);
@@ -37,7 +37,7 @@
     return (PGFunction) NSAddressOfSymbol(symbol);
 }

-const char *pg_dlerror(void)
+char *pg_dlerror(void)
 {
     return "no error message available";
 }
Index: src/backend/port/dynloader/darwin.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/port/dynloader/darwin.h,v
retrieving revision 1.2
diff -u -r1.2 darwin.h
--- src/backend/port/dynloader/darwin.h    2000/11/09 19:00:50    1.2
+++ src/backend/port/dynloader/darwin.h    2000/11/29 05:48:51
@@ -2,7 +2,7 @@

 #include "fmgr.h"

-void       *pg_dlopen(const char *filename);
-PGFunction    pg_dlsym(void *handle, const char *funcname);
+void*        pg_dlopen(char *filename);
+PGFunction    pg_dlsym(void *handle, char *funcname);
 void        pg_dlclose(void *handle);
-const char *pg_dlerror(void);
+char*        pg_dlerror(void);
Index: src/backend/storage/buffer/s_lock.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/buffer/s_lock.c,v
retrieving revision 1.26
diff -u -r1.26 s_lock.c
--- src/backend/storage/buffer/s_lock.c    2000/11/28 23:27:55    1.26
+++ src/backend/storage/buffer/s_lock.c    2000/11/29 05:48:51
@@ -119,6 +119,31 @@

 #endif     /* __m68k__ */

+#if defined(darwin) && defined(__ppc__)
+static void
+tas_dummy()
+{
+       __asm__("               \n\
+               .globl  tas     \n\
+               .globl  _tas    \n\
+_tas:                          \n\
+tas:                           \n\
+               lwarx   r5,0,r3 \n\
+               cmpwi   r5,0    \n\
+               bne     fail    \n\
+               addi    r5,r5,1 \n\
+               stwcx.  r5,0,r3 \n\
+               beq     success \n\
+fail:          li      r3,1    \n\
+               blr             \n\
+success:                       \n\
+               li r3,0         \n\
+               blr             \n\
+    ");
+}
+
+#endif  /* __ppc__ && darwin */
+
 #if defined(__powerpc__)
 /* Note: need a nice gcc constrained asm version so it can be inlined */
 static void
Index: src/backend/storage/ipc/ipc.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v
retrieving revision 1.54
diff -u -r1.54 ipc.c
--- src/backend/storage/ipc/ipc.c    2000/11/28 23:27:56    1.54
+++ src/backend/storage/ipc/ipc.c    2000/11/29 05:48:51
@@ -52,6 +52,10 @@
 #include <sys/ipc.h>
 #endif

+#if defined(darwin)
+#include "../backend/port/darwin/sem.h"
+#endif
+

 /*
  * This flag is set during proc_exit() to change elog()'s behavior,
Index: src/backend/storage/ipc/spin.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/ipc/spin.c,v
retrieving revision 1.26
diff -u -r1.26 spin.c
--- src/backend/storage/ipc/spin.c    2000/11/28 23:27:56    1.26
+++ src/backend/storage/ipc/spin.c    2000/11/29 05:48:51
@@ -21,7 +21,7 @@
 #include "postgres.h"

 #include <errno.h>
-#ifndef HAS_TEST_AND_SET
+#if !defined(HAS_TEST_AND_SET) && defined(HAVE_SYS_SEM_H)
 #include <sys/sem.h>
 #endif

Index: src/backend/storage/lmgr/proc.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v
retrieving revision 1.84
diff -u -r1.84 proc.c
--- src/backend/storage/lmgr/proc.c    2000/11/28 23:27:56    1.84
+++ src/backend/storage/lmgr/proc.c    2000/11/29 05:48:51
@@ -69,6 +69,11 @@
 #include <sys/sem.h>
 #endif

+/* Darwin needs a shim for semctl */
+#if defined(darwin)
+#include "../backend/port/darwin/sem.h"
+#endif
+
 #include "storage/proc.h"

 void        HandleDeadLock(SIGNAL_ARGS);
Index: src/include/port/darwin.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/port/darwin.h,v
retrieving revision 1.1
diff -u -r1.1 darwin.h
--- src/include/port/darwin.h    2000/10/31 19:55:19    1.1
+++ src/include/port/darwin.h    2000/11/29 05:48:51
@@ -1,5 +1,10 @@
+#define darwin
+
+#if defined(__ppc__)
 #define HAS_TEST_AND_SET
-#if defined(__powerpc__)
+#endif
+
+#if defined(__ppc__)
 typedef unsigned int slock_t;
 #else
 typedef unsigned char slock_t;
Index: src/template/darwin
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/template/darwin,v
retrieving revision 1.1
diff -r1.1 darwin
1c1,2
< # regular cpp is broken in current development releases
---
> # traditional-cpp means "use gnu cpp" on darwin
> # this should change to -no-cpp-precomp eventually
2a4
>
4c6,7
< CFLAGS=-O0
---
> #CFLAGS=-O2
>

--
bierman@apple.com

"4 out of 5 people with the wrong hardware want to run Mac OS X because..."
http://www.newertech.com/oscompatibility/osxinfo.html



pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: pg_dump.save_pkey_name.patch
Next
From: Tom Lane
Date:
Subject: Re: darwin pgsql patches